package cn.laixueit.resource.feign.result;

import cn.hutool.http.HttpStatus;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;

/**
 * @author duxiang
 * @date 2024/2/18 9:46
 */
@Data
public class R extends HashMap<String,Object> implements Serializable {
    R() {
        put("code", 0);
        put("msg", "success");
    }

    public static R ok() {
        R r = new R();
        return r;
    }

    public static R data(Object obj) {
        R r = new R();
        r.put("data", obj);
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.put("msg", msg);
        return r;
    }
    public static R error() {
        return error(HttpStatus.HTTP_INTERNAL_ERROR, "Internal Server Error.");
    }

    public static R error(String msg) {
        return error(HttpStatus.HTTP_INTERNAL_ERROR, msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

}
